//
//  HomeSortMenuView.m
//  SameWorld
//
//  Created by 杨旭 on 2017/3/17.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "HomeSortMenuView.h"

@interface HomeSortMenuView ()
@property (nonatomic ,strong) NSArray *titleArray;
@property (nonatomic ,strong) NSArray *imageArray;

@end

@implementation HomeSortMenuView

- (instancetype)initWithFrame:(CGRect)frame withTitleArray:(NSArray *)titleArray imageArray:(NSArray *)imageArray {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.titleArray = titleArray;
        self.imageArray = imageArray;
        [self setup];
    }
    return self;
}

- (void)setup {

    for (int i = 0; i < 4; i ++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(self.frame.size.width/4*i + self.frame.size.width/4/2-10,self.frame.size.height - 55, 20, 20);
        [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.imageArray[i]]] forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(menuBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
        btn.tag = 1000 + i;
        [self addSubview:btn];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:(CGRectMake(self.frame.size.width/4*i + self.frame.size.width/4/2-38, self.frame.size.height-35, 76, 20))];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.text = _titleArray[i];
        lab.textColor = [UIColor blackColor];
//        lab.font = [UIFont boldSystemFontOfSize:10];
        lab.font = [UIFont systemFontOfSize:14];
        [self addSubview:lab];
        
    }
    
    for (int i = 0 ; i < 4; i ++) {
        // 分割线
        if (i > 0 && self.frame.size.height > 16) {
            UIView *line = [[UIView alloc] initWithFrame:(CGRectMake(kScreenWidth / 4 *i, 18, 1, self.frame.size.height - 36))];
            line.backgroundColor = [UIColor grayColor];
            [self addSubview:line];
        }
    }

}

- (void)menuBtnClick:(UIButton *)sender {
    
    self.sortMenuBtn(sender.tag);
}


- (instancetype)initWithMineMoneySortMenuFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setAmountUI];
    }
    return self;
}

- (void)setAmountUI {
    
    NSArray *arr = @[@"积分",@"帖子",@"签到"];
    for (int i = 0; i < 3; i ++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(self.frame.size.width/3*i, 0, self.frame.size.width/3, 60);
        //        btn.backgroundColor = [UIColor randomColor];
        [btn setTitle:arr[i] forState:(UIControlStateNormal)];
        [btn setTitleColor:color_textOne forState:(UIControlStateNormal)];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        btn.titleEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 0);
        btn.tag = 200 + i;
        [btn addTarget:self action:@selector(mineMoneySortMenuClicked:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:btn];
        
      
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width/3 *i, self.frame.size.height - 50, self.frame.size.width/3, 20)];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.textColor = color_blueColor;
        lab.font = [UIFont systemFontOfSize:15.0];
        lab.text = @"0";
        [self addSubview:lab];
    
        
    }
    
    for (int i = 0 ; i < 3; i ++) {
        // 分割线
        if (i > 0 && self.frame.size.height > 16) {
            UIView *line = [[UIView alloc] initWithFrame:(CGRectMake(kScreenWidth / 3 *i, 18, 1, self.frame.size.height - 36))];
            line.backgroundColor = [UIColor py_colorWithHexString:@"dcdcdc"];
            [self addSubview:line];
        }
    }
}

- (void)mineMoneySortMenuClicked:(UIButton *)sender {
    self.mineMoneySortMenu(sender.tag - 200);
}


@end
